package com.urea.web.controller.urea;

import com.urea.common.annotation.Log;
import com.urea.common.core.controller.BaseController;
import com.urea.common.core.domain.AjaxResult;
import com.urea.common.core.page.TableDataInfo;
import com.urea.common.enums.BusinessType;
import com.urea.common.utils.poi.ExcelUtil;
import com.urea.system.domain.FileInfo;
import com.urea.system.domain.FileInfo;
import com.urea.system.service.IFileInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 文件信息Controller
 * 
 * @author liuzd
 * @date 2023-08-01
 */
@RestController
@RequestMapping("/fileInfo")
@Api(tags = "文件相关")
public class FileInfoController extends BaseController
{
    @Autowired
    private IFileInfoService fileInfoService;

    /**
     * 查询文件列表
     */
//    @PreAuthorize("@ss.hasPermi('FileInfo:list')")
    @GetMapping("/list")
    @ApiOperation("查询文件列表")
    public TableDataInfo list(FileInfo fileInfo)
    {
        startPage();
        List<FileInfo> list = fileInfoService.selectFileInfoList(fileInfo);
        return getDataTable(list);
    }
    

    /**
     * 获取文件详细信息
     */
//    @PreAuthorize("@ss.hasPermi('FileInfo:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("查询文件信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(fileInfoService.selectFileInfoById(id));
    }

    /**
     * 新增文件
     */
//    @PreAuthorize("@ss.hasPermi('FileInfo:add')")
    @Log(title = "文件", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增文件")
    public AjaxResult add(@RequestBody FileInfo fileInfo)
    {
        return toAjax(fileInfoService.insertFileInfo(fileInfo));
    }

    /**
     * 修改文件
     */
//    @PreAuthorize("@ss.hasPermi('FileInfo:edit')")
    @Log(title = "文件", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改文件")
    public AjaxResult edit(@RequestBody FileInfo FileInfo)
    {
        return toAjax(fileInfoService.updateFileInfo(FileInfo));
    }

    /**
     * 删除文件
     */
    @PreAuthorize("@ss.hasPermi('FileInfo:remove')")
    @Log(title = "文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除文件")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fileInfoService.deleteFileInfoByIds(ids));
    }

    @GetMapping("/download/{id}")
    @ApiOperation("文件下载")
    public void downLoad(HttpServletResponse response,@PathVariable("id")Long id){
        fileInfoService.downLoad(response,id);
    }
}
